`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Module: vga_display                                                          //
// Author: Zhiyuan Lin & Cheng Yang                                             //
// Date: 4/26/2014                                                              //
//////////////////////////////////////////////////////////////////////////////////
module vga_display(melody, clk, gameover_flag, Sim_Restart,
	                Sim_Btn1, Sim_Btn2, Sim_Btn3, 
	                Sim_Btn4, Sim_Pause, Sim_Start, Btn_turbo,
						 R, G, B, HS, VS);  
   input clk;		
	input [5:0] melody;
	input Sim_Btn1, Sim_Btn2, Sim_Btn3, Sim_Restart,
	      Sim_Btn4, Sim_Pause, Sim_Start, Btn_turbo;
/*	wire De_Sim_Btn1, De_Sim_Btn2, De_Sim_Btn3, De_Sim_Btn4;*/
//RESET
	wire reset;
	assign reset = ~Sim_Start;
	
   output reg [2:0] R, G;
   output reg [1:0] B;
   output HS;
   output VS;
//when the player get 20 errors, gameover_flag = 1 
	
	output reg gameover_flag;
	
   wire [10:0] hcount, vcount;
   wire blank;                       				

//clockdivider
   wire o_clk, o_clk1, o_clk2, o_clk3, o_clk4;
	wire clk_25Mhz;
	wire clk_1KHz;
	wire clk_800Hz;
	wire clk_700Hz;
	
//lfsr	
	reg [9:0] M1, M2, M3, M4;
	reg [9:0] M5, M6, M7, M8;
	reg [9:0] M9, M10, M11, M12;
	reg [9:0] M13, M14, M15, M16;
	
	wire [3:0] rand1, rand2, rand3, rand4;
	wire [3:0] rand5, rand6, rand7, rand8;
	wire [3:0] rand9, rand10, rand11, rand12;
	wire [3:0] rand13, rand14, rand15, rand16;
/*   reg [3:0] seed1, seed2, seed3, seed4;*/
	
//debouncer
/*	wire step1, step2, step3, step4;*/
	reg start1, start2, start3, start4;
	reg start5, start6, start7, start8;
	reg start9, start10, start11, start12;
	reg start13, start14, start15, start16;

//scoring
	reg [11:0] score, scoretwo;// 2^11=2048 >= 1000 it works
	reg [9:0] wrong, wrongs;
	reg [1:0] state, nextstate;
	wire score1, score2, score3, score4;
	wire wrong1, wrong2, wrong3, wrong4;
	
	reg [2:0] column1, column2, column3, column4;
	reg [100:0] figcount;
	reg [19:0] scorecount;
	
	reg [3:0] thousands, hundreds, tens, ones;
	reg [3:0] w_hundreds, w_tens, w_ones;
	
	wire figure0_1, figure0_2, figure0_3, figure0_4;
	
   //SCORE
	reg [15:0] sprite_S [0:15];
	reg [15:0] sprite_C [0:15];
	reg [15:0] sprite_O [0:15];
	reg [15:0] sprite_R [0:15];
	reg [15:0] sprite_E [0:15];
	reg [15:0] sprite_colon [0:15];
	//NUMBERS
	reg [15:0] sprite_0 [0:15];
	reg [15:0] sprite_1 [0:15];
	reg [15:0] sprite_2 [0:15];
	reg [15:0] sprite_3 [0:15];
	reg [15:0] sprite_4 [0:15];
	reg [15:0] sprite_5 [0:15];
	reg [15:0] sprite_6 [0:15];
	reg [15:0] sprite_7 [0:15];
	reg [15:0] sprite_8 [0:15];
	reg [15:0] sprite_9 [0:15];
	//3-bit SCORE
	reg [15:0] digit_0 [0:15];
	reg [15:0] digit_1 [0:15];
	reg [15:0] digit_2 [0:15];
	//3-bit ERROR
	reg [15:0] digit_3 [0:15];
	reg [15:0] digit_4 [0:15];
	reg [15:0] digit_5 [0:15];
	//4 ARROW

	reg [35:0] arrow_d [0:35];
	reg [35:0] arrow_l [0:35];
	reg [35:0] arrow_r [0:35];
	reg [35:0] arrow_u [0:35];

//rows for the sprite
	reg [15:0] letter1_row, letter2_row, letter3_row, 
	           letter4_row, letter5_row, letter6_row;
	reg [15:0] letter7_row, letter8_row, letter9_row, 
	           letter10_row, letter11_row, letter12_row;	
	reg [35:0] figure11_1, figure11_2, figure11_3, figure11_4,
              figure11_5, figure11_6, figure11_7, figure11_8,
				  figure11_9, figure11_10, figure11_11, figure11_12,
				  figure11_13, figure11_14, figure11_15, figure11_16;
	reg [35:0] figure22_1, figure22_2, figure22_3, figure22_4,
              figure22_5, figure22_6, figure22_7, figure22_8,
				  figure22_9, figure22_10, figure22_11, figure22_12,
				  figure22_13, figure22_14, figure22_15, figure22_16;
	reg [35:0] figure33_1, figure33_2, figure33_3, figure33_4,
              figure33_5, figure33_6, figure33_7, figure33_8,
				  figure33_9, figure33_10, figure33_11, figure33_12,
				  figure33_13, figure33_14, figure33_15, figure33_16;
	reg [35:0] figure44_1, figure44_2, figure44_3, figure44_4,
              figure44_5, figure44_6, figure44_7, figure44_8,
				  figure44_9, figure44_10, figure44_11, figure44_12,
				  figure44_13, figure44_14, figure44_15, figure44_16;
				  
				  
				  
	reg [15:0] digit_0_row, digit_1_row, digit_2_row, digit_21_row; 
	reg [15:0] digit_3_row, digit_4_row, digit_5_row;	
	reg [35:0] arrow_u_row, arrow_d_row, arrow_l_row, arrow_r_row;

		
	reg letter1_on, letter2_on, letter3_on, 
	    letter4_on, letter5_on, letter6_on;
	reg letter7_on, letter8_on, letter9_on, 
	    letter10_on, letter11_on, letter12_on;	
   reg figure1_1, figure1_2, figure1_3, figure1_4,
       figure1_5, figure1_6, figure1_7, figure1_8,
		 figure1_9, figure1_10, figure1_11, figure1_12,
		 figure1_13, figure1_14, figure1_15, figure1_16;
	reg figure2_1, figure2_2, figure2_3, figure2_4,
       figure2_5, figure2_6, figure2_7, figure2_8,
		 figure2_9, figure2_10, figure2_11, figure2_12,
		 figure2_13, figure2_14, figure2_15, figure2_16;
	reg figure3_1, figure3_2, figure3_3, figure3_4,
       figure3_5, figure3_6, figure3_7, figure3_8,
		 figure3_9, figure3_10, figure3_11, figure3_12,
		 figure3_13, figure3_14, figure3_15, figure3_16;
	reg figure4_1, figure4_2, figure4_3, figure4_4,
       figure4_5, figure4_6, figure4_7, figure4_8,
		 figure4_9, figure4_10, figure4_11, figure4_12,
		 figure4_13, figure4_14, figure4_15, figure4_16;
				  
	reg digit_0_on, digit_1_on, digit_2_on, digit_21_on;
	reg digit_3_on, digit_4_on, digit_5_on;		

	initial begin

		start1 = 1'b0;
		start2 = 1'b0;
		start3 = 1'b0;
		start4 = 1'b0;
	   start5 = 1'b0;
		start6 = 1'b0;
		start7 = 1'b0;
		start8 = 1'b0;
		start9 = 1'b0;
		start10 = 1'b0;
		start11 = 1'b0;
		start12 = 1'b0;
	   start13 = 1'b0;
		start14 = 1'b0;
		start15 = 1'b0;
		start16 = 1'b0;
		
		column1 = 3'b000;
		column2 = 3'b001 ;
		column3 = 3'b010;
		column4 = 3'b011;
		
		score = 0;
		wrong = 0;
	end

	 audio_arrow A_1(melody, rand1, reset, M1);
	 audio_arrow A_2(melody, rand2, reset, M2);
	 audio_arrow A_3(melody, rand3, reset, M3);
	 audio_arrow A_4(melody, rand4, reset, M4);
	 audio_arrow A_5(melody, rand5, reset, M5);
	 audio_arrow A_6(melody, rand6, reset, M6);
	 audio_arrow A_7(melody, rand7, reset, M7);
	 audio_arrow A_8(melody, rand8, reset, M8);
	 audio_arrow A_9(melody, rand9, reset, M9);
	 audio_arrow A_10(melody, rand10, reset, M10);
	 audio_arrow A_11(melody, rand11, reset, M11);
	 audio_arrow A_12(melody, rand12, reset, M12);
	 audio_arrow A_13(melody, rand13, reset, M13);
	 audio_arrow A_14(melody, rand14, reset, M14);
	 audio_arrow A_15(melody, rand15, reset, M15);
	 audio_arrow A_16(melody, rand16, reset, M16);
   
	vga_controller_640_60	VC_0(clk_25Mhz, HS, VS, hcount, vcount, blank);
	
   clock_div	CD_DE (, clk_1KHz, clk_5Hz, clk_800Hz, clk_700Hz, clk);
	
	ClockDivider_25MHz CD_0(clk, clk_25Mhz);
   ClockDivider CD_1(clk, o_clk, Sim_Pause); //moving box!! 
	//ClockDivider_2 CD_2(clk, o_clk3, 4'd4);	// scoring module!! this clock goes to accuracy checker module
	//ClockDivider_2 CD_3(clk, o_clk4, 4'd5);	// scoring!! this clock runs our score keeping, twice as fast as o_clk3
	
	scoring S_1(clk_700Hz, rand1, rand2, rand3, rand4, 
	            rand5, rand6, rand7, rand8,
	            rand9, rand10, rand11, rand12,
	            rand13, rand14, rand15, rand16,
	            M1, M2, M3, M4, 
					M5, M6, M7, M8, 
					M9, M10, M11, M12, 
					M13, M14, M15, M16,
					Sim_Btn1, column1, score1, wrong1);
	scoring S_2(clk_700Hz, rand1, rand2, rand3, rand4, 
	            rand5, rand6, rand7, rand8,
	            rand9, rand10, rand11, rand12,
	            rand13, rand14, rand15, rand16,
               M1, M2, M3, M4,
					M5, M6, M7, M8, 
					M9, M10, M11, M12, 
					M13, M14, M15, M16,
					Sim_Btn2, column2, score2, wrong2);
	scoring S_3(clk_700Hz, rand1, rand2, rand3, rand4, 
	            rand5, rand6, rand7, rand8,
	            rand9, rand10, rand11, rand12,
	            rand13, rand14, rand15, rand16,
               M1, M2, M3, M4,
					M5, M6, M7, M8, 
					M9, M10, M11, M12, 
					M13, M14, M15, M16,
					Sim_Btn3, column3, score3, wrong3);
	scoring S_4(clk_700Hz, rand1, rand2, rand3, rand4, 
	            rand5, rand6, rand7, rand8,
	            rand9, rand10, rand11, rand12,
	            rand13, rand14, rand15, rand16,
	            M1, M2, M3, M4,
					M5, M6, M7, M8, 
					M9, M10, M11, M12, 
					M13, M14, M15, M16,
					Sim_Btn4, column4, score4, wrong4);

  //4 Squares
	assign figure0_1 = ~blank & (hcount==65 & vcount>=430 & vcount<=430+35
		|| hcount==65+39 & vcount>=430 & vcount<=430+35
		|| vcount==430 & hcount>=65 & hcount<=65+39
		|| vcount==430+35 & hcount>=65 & hcount<=65+39);
		
	assign figure0_2 = ~blank & (hcount==208 & vcount>=430 & vcount<=430+35
		|| hcount==208+39 & vcount>=430 & vcount<=430+35
		|| vcount==430 & hcount>=208 & hcount<=208+39
		|| vcount==430+35 & hcount>=208 & hcount<=208+39);
		
	assign figure0_3 = ~blank & (hcount==351 & vcount>=430 & vcount<=430+35
		|| hcount==351+39 & vcount>=430 & vcount<=430+35
		|| vcount==430 & hcount>=351 & hcount<=351+39
		|| vcount==430+35 & hcount>=351 & hcount<=351+39);
		
	assign figure0_4 = ~blank & (hcount==494 & vcount>=430 & vcount<=430+35
		|| hcount==494+39 & vcount>=430 & vcount<=430+35
		|| vcount==430 & hcount>=494 & hcount<=494+39
		|| vcount==430+35 & hcount>=494 & hcount<=494+39);
		
	//SCORE & ERROR	
	 integer i;
	 reg s1;
	 
	 always@(posedge clk_800Hz)
		begin
			if (i<2)
				i<=i+1;
			else
				begin
					i<=0;
					s1<=~s1;
				end			
		end	
		
		
		
	always @ (posedge /*o_clk4*//*s1*/clk_700Hz) begin
	    
		if (Sim_Restart == 1)
			begin
				score = 0;

			end
		else
			begin
				score = score + score1 + score2 + score3 + score4;
				scoretwo = score/2;
			end

	end
		
	always @ (posedge /*o_clk4*//*s1*/s1) begin
	 if (Sim_Restart == 1)
		begin
			wrong = 0;
			gameover_flag = 0;
		end
	  else begin
	  	wrong = wrong + wrong1 + wrong2 + wrong3 + wrong4;
		wrongs = wrong/2;	
		if (wrong == 80)
		   begin
			 gameover_flag = 1;
			end
	  end
	 
	end
	
	
	
   always @ (posedge clk_25Mhz) begin
	
		sprite_S[ 0] <= 16'b0000000000000000; 
		sprite_S[ 1] <= 16'b0000011111100000;
		sprite_S[ 2] <= 16'b0000011111100000; 
		sprite_S[ 3] <= 16'b0001100000011000; 
		sprite_S[ 4] <= 16'b0001100000011000; 
		sprite_S[ 5] <= 16'b0001100000000000; 
		sprite_S[ 6] <= 16'b0001100000000000; 
		sprite_S[ 7] <= 16'b0000011111100000; 
		sprite_S[ 8] <= 16'b0000011111100000; 
		sprite_S[ 9] <= 16'b0000000000011000; 
		sprite_S[10] <= 16'b0000000000011000; 
		sprite_S[11] <= 16'b0001100000011000; 
		sprite_S[12] <= 16'b0001100000011000;
		sprite_S[13] <= 16'b0000011111100000;
		sprite_S[14] <= 16'b0000011111100000;
		sprite_S[15] <= 16'b0000000000000000;//S
		
		sprite_C[ 0] <= 16'b0000000000000000; 
		sprite_C[ 1] <= 16'b0000011111100000; 
		sprite_C[ 2] <= 16'b0000011111100000; 
		sprite_C[ 3] <= 16'b0001100000011000; 
		sprite_C[ 4] <= 16'b0001100000011000; 
		sprite_C[ 5] <= 16'b0001100000000000; 
		sprite_C[ 6] <= 16'b0001100000000000; 
		sprite_C[ 7] <= 16'b0001100000000000; 
		sprite_C[ 8] <= 16'b0001100000000000; 
		sprite_C[ 9] <= 16'b0001100000000000; 
		sprite_C[10] <= 16'b0001100000000000; 
		sprite_C[11] <= 16'b0001100000011000; 
		sprite_C[12] <= 16'b0001100000011000; 
		sprite_C[13] <= 16'b0000011111100000; 
		sprite_C[14] <= 16'b0000011111100000; 
		sprite_C[15] <= 16'b0000000000000000; //C
			
		sprite_O[ 0] <= 16'b0000000000000000; 
		sprite_O[ 1] <= 16'b0000011111100000; 
		sprite_O[ 2] <= 16'b0000011111100000; 
		sprite_O[ 3] <= 16'b0001100000011000; 
		sprite_O[ 4] <= 16'b0001100000011000; 
		sprite_O[ 5] <= 16'b0001100000011000; 
		sprite_O[ 6] <= 16'b0001100000011000; 
		sprite_O[ 7] <= 16'b0001100000011000; 
		sprite_O[ 8] <= 16'b0001100000011000;
		sprite_O[ 9] <= 16'b0001100000011000; 
		sprite_O[10] <= 16'b0001100000011000; 
		sprite_O[11] <= 16'b0001100000011000; 
		sprite_O[12] <= 16'b0001100000011000; 
		sprite_O[13] <= 16'b0000011111100000;
		sprite_O[14] <= 16'b0000011111100000;
		sprite_O[15] <= 16'b0000000000000000;//O

		sprite_R[ 0] <= 16'b0000000000000000; 
		sprite_R[ 1] <= 16'b0001111111100000; 
		sprite_R[ 2] <= 16'b0001111111100000; 
		sprite_R[ 3] <= 16'b0001100000011000; 
		sprite_R[ 4] <= 16'b0001100000011000; 
		sprite_R[ 5] <= 16'b0001100000011000; 
		sprite_R[ 6] <= 16'b0001100000011000; 
		sprite_R[ 7] <= 16'b0001111111100000; 
		sprite_R[ 8] <= 16'b0001111111100000; 
		sprite_R[ 9] <= 16'b0001100110000000; 
		sprite_R[10] <= 16'b0001100110000000; 
		sprite_R[11] <= 16'b0001100001100000; 
		sprite_R[12] <= 16'b0001100001100000; 
		sprite_R[13] <= 16'b0001100000011000; 
		sprite_R[14] <= 16'b0001100000011000; 
		sprite_R[15] <= 16'b0000000000000000;//R


		sprite_E[ 0] <= 16'b0000000000000000; 
		sprite_E[ 1] <= 16'b0001111111111000; 
		sprite_E[ 2] <= 16'b0001111111111000; 
		sprite_E[ 3] <= 16'b0001100000000000; 
		sprite_E[ 4] <= 16'b0001100000000000; 
		sprite_E[ 5] <= 16'b0001100000000000; 
		sprite_E[ 6] <= 16'b0001100000000000; 
		sprite_E[ 7] <= 16'b0001111111100000; 
		sprite_E[ 8] <= 16'b0001111111100000; 
		sprite_E[ 9] <= 16'b0001100000000000; 
		sprite_E[10] <= 16'b0001100000000000; 
		sprite_E[11] <= 16'b0001100000000000; 
		sprite_E[12] <= 16'b0001100000000000; 
		sprite_E[13] <= 16'b0001111111111000; 
		sprite_E[14] <= 16'b0001111111111000; 
		sprite_E[15] <= 16'b0000000000000000; //E

		sprite_colon[ 0] <= 16'b0000000000000000;
		sprite_colon[ 1] <= 16'b0000000000000000;
		sprite_colon[ 2] <= 16'b0000000000000000;
		sprite_colon[ 3] <= 16'b0000000000000000;
		sprite_colon[ 4] <= 16'b0000000110000000;
		sprite_colon[ 5] <= 16'b0000000110000000;
		sprite_colon[ 6] <= 16'b0000000000000000;
		sprite_colon[ 7] <= 16'b0000000000000000;
		sprite_colon[ 8] <= 16'b0000000000000000;
		sprite_colon[ 9] <= 16'b0000000000000000;
		sprite_colon[10] <= 16'b0000000110000000;
		sprite_colon[11] <= 16'b0000000110000000;
		sprite_colon[12] <= 16'b0000000000000000;
		sprite_colon[13] <= 16'b0000000000000000;
		sprite_colon[14] <= 16'b0000000000000000;
		sprite_colon[15] <= 16'b0000000000000000;//:
		
		sprite_0[ 0] <= 16'b0000000000000000;
		sprite_0[ 1] <= 16'b0000011111100000;
		sprite_0[ 2] <= 16'b0000011111100000;
		sprite_0[ 3] <= 16'b0001100000011000;
		sprite_0[ 4] <= 16'b0001100000011000;
		sprite_0[ 5] <= 16'b0001100001111000;
		sprite_0[ 6] <= 16'b0001100001111000;
		sprite_0[ 7] <= 16'b0001100110011000;
		sprite_0[ 8] <= 16'b0001100110011000;
		sprite_0[ 9] <= 16'b0001111000011000;
		sprite_0[10] <= 16'b0001111000011000;
		sprite_0[11] <= 16'b0001100000011000;
		sprite_0[12] <= 16'b0001100000011000;
		sprite_0[13] <= 16'b0000011111100000;
		sprite_0[14] <= 16'b0000011111100000;
		sprite_0[15] <= 16'b0000000000000000;//0
		
		
		sprite_1[ 0] <= 16'b0000000000000000;
		sprite_1[ 1] <= 16'b0000000110000000;
		sprite_1[ 2] <= 16'b0000000110000000;
		sprite_1[ 3] <= 16'b0000011110000000;
		sprite_1[ 4] <= 16'b0000011110000000;
		sprite_1[ 5] <= 16'b0000000110000000;
		sprite_1[ 6] <= 16'b0000000110000000;
		sprite_1[ 7] <= 16'b0000000110000000;
		sprite_1[ 8] <= 16'b0000000110000000;
		sprite_1[ 9] <= 16'b0000000110000000;
		sprite_1[10] <= 16'b0000000110000000;
		sprite_1[11] <= 16'b0000000110000000;
		sprite_1[12] <= 16'b0000000110000000;
		sprite_1[13] <= 16'b0000011111100000;
		sprite_1[14] <= 16'b0000011111100000;
		sprite_1[15] <= 16'b0000000000000000;//1
		
		sprite_2[ 0] <= 16'b0000000000000000;
		sprite_2[ 1] <= 16'b0000011111100000;
		sprite_2[ 2] <= 16'b0000011111100000;
		sprite_2[ 3] <= 16'b0001100000011000;
		sprite_2[ 4] <= 16'b0001100000011000;
		sprite_2[ 5] <= 16'b0000000000011000;
		sprite_2[ 6] <= 16'b0000000000011000;
		sprite_2[ 7] <= 16'b0000000111100000;
		sprite_2[ 8] <= 16'b0000000111100000;
		sprite_2[ 9] <= 16'b0000011000000000;
		sprite_2[10] <= 16'b0000011000000000;
		sprite_2[11] <= 16'b0001100000000000;
		sprite_2[12] <= 16'b0001100000000000;
		sprite_2[13] <= 16'b0001111111111000;
		sprite_2[14] <= 16'b0001111111111000;
		sprite_2[15] <= 16'b0000000000000000;//2
		
		sprite_3[ 0] <= 16'b0000000000000000;
		sprite_3[ 1] <= 16'b0000011111100000;
		sprite_3[ 2] <= 16'b0000011111100000;
		sprite_3[ 3] <= 16'b0001100000011000;
		sprite_3[ 4] <= 16'b0001100000011000;
		sprite_3[ 5] <= 16'b0000000000011000;
		sprite_3[ 6] <= 16'b0000000000011000;
		sprite_3[ 7] <= 16'b0000000111100000;
		sprite_3[ 8] <= 16'b0000000111100000;
		sprite_3[ 9] <= 16'b0000000000011000;
		sprite_3[10] <= 16'b0000000000011000;
		sprite_3[11] <= 16'b0001100000011000;
		sprite_3[12] <= 16'b0001100000011000;
		sprite_3[13] <= 16'b0000011111100000;
		sprite_3[14] <= 16'b0000011111100000;
		sprite_3[15] <= 16'b0000000000000000;//3
		
		sprite_4[ 0] <= 16'b0000000000000000;
		sprite_4[ 1] <= 16'b0000000110000000;
		sprite_4[ 2] <= 16'b0000000110000000;
		sprite_4[ 3] <= 16'b0000011110000000;
		sprite_4[ 4] <= 16'b0000011110000000;
		sprite_4[ 5] <= 16'b0000110110000000;
		sprite_4[ 6] <= 16'b0001100110000000;
		sprite_4[ 7] <= 16'b0011000110000000;
		sprite_4[ 8] <= 16'b0110000110000000;
		sprite_4[ 9] <= 16'b0110000110000000;
		sprite_4[10] <= 16'b0111111111111100;
		sprite_4[11] <= 16'b0000000110000000;
		sprite_4[12] <= 16'b0000000110000000;
		sprite_4[13] <= 16'b0000011111100000;
		sprite_4[14] <= 16'b0000011111100000;
		sprite_4[15] <= 16'b0000000000000000;//4
		
		sprite_5[ 0] <= 16'b0000000000000000;
		sprite_5[ 1] <= 16'b0001111111111000;
		sprite_5[ 2] <= 16'b0001111111111000;
		sprite_5[ 3] <= 16'b0001100000000000;
		sprite_5[ 4] <= 16'b0001100000000000;
		sprite_5[ 5] <= 16'b0001100000000000;
		sprite_5[ 6] <= 16'b0001100000000000;
		sprite_5[ 7] <= 16'b0001111111110000;
		sprite_5[ 8] <= 16'b0001111111111000;
		sprite_5[ 9] <= 16'b0000000000011000;
		sprite_5[10] <= 16'b0000000000001100;
		sprite_5[11] <= 16'b0000000000001100;
		sprite_5[12] <= 16'b0001100000011000;
		sprite_5[13] <= 16'b0001111111111000;
		sprite_5[14] <= 16'b0000111111110000;
		sprite_5[15] <= 16'b0000000000000000;//5
		
		sprite_6[ 0] <= 16'b0000000000000000;
		sprite_6[ 1] <= 16'b0000111111110000;
		sprite_6[ 2] <= 16'b0001111111111000;
		sprite_6[ 3] <= 16'b0001100000000000;
		sprite_6[ 4] <= 16'b0011100000000000;
		sprite_6[ 5] <= 16'b0011100000000000;
		sprite_6[ 6] <= 16'b0011100000000000;
		sprite_6[ 7] <= 16'b0011111111110000;
		sprite_6[ 8] <= 16'b0011111111111000;
		sprite_6[ 9] <= 16'b0011100000011000;
		sprite_6[10] <= 16'b0011000000001100;
		sprite_6[11] <= 16'b0011000000001100;
		sprite_6[12] <= 16'b0011100000011100;
		sprite_6[13] <= 16'b0001111111111000;
		sprite_6[14] <= 16'b0000111111110000;
		sprite_6[15] <= 16'b0000000000000000;//6
		
		sprite_7[ 0] <= 16'b0000000000000000;
		sprite_7[ 1] <= 16'b0011111111111110;
		sprite_7[ 2] <= 16'b0011111111111110;
		sprite_7[ 3] <= 16'b0000000000001110;
		sprite_7[ 4] <= 16'b0000000000011100;
		sprite_7[ 5] <= 16'b0000000000011100;
		sprite_7[ 6] <= 16'b0000000000111000;
		sprite_7[ 7] <= 16'b0000000000111000;
		sprite_7[ 8] <= 16'b0000000001110000;
		sprite_7[ 9] <= 16'b0000000001110000;
		sprite_7[10] <= 16'b0000000011100000;
		sprite_7[11] <= 16'b0000000011100000;
		sprite_7[12] <= 16'b0000000111000000;
		sprite_7[13] <= 16'b0000000111000000;
		sprite_7[14] <= 16'b0000001110000000;
		sprite_7[15] <= 16'b0000000000000000;//7
		
		sprite_8[ 0] <= 16'b0000000000000000;
		sprite_8[ 1] <= 16'b0000111111110000;
		sprite_8[ 2] <= 16'b0001111111111000;
		sprite_8[ 3] <= 16'b0001100000001100;
		sprite_8[ 4] <= 16'b0011100000001100;
		sprite_8[ 5] <= 16'b0011100000001100;
		sprite_8[ 6] <= 16'b0011100000011100;
		sprite_8[ 7] <= 16'b0001111111111000;
		sprite_8[ 8] <= 16'b0001111111111000;
		sprite_8[ 9] <= 16'b0011100000011100;
		sprite_8[10] <= 16'b0011000000001100;
		sprite_8[11] <= 16'b0011000000001100;
		sprite_8[12] <= 16'b0011100000011100;
		sprite_8[13] <= 16'b0001111111111000;
		sprite_8[14] <= 16'b0000111111110000;
		sprite_8[15] <= 16'b0000000000000000;//8
		
		sprite_9[ 0] <= 16'b0000000000000000;
		sprite_9[ 1] <= 16'b0000011111100000;
		sprite_9[ 2] <= 16'b0000111111110000;
		sprite_9[ 3] <= 16'b0001100000011000;
		sprite_9[ 4] <= 16'b0001100000011000;
		sprite_9[ 5] <= 16'b0001100000011000;
		sprite_9[ 6] <= 16'b0001100000011000;
		sprite_9[ 7] <= 16'b0001111111111000;
		sprite_9[ 8] <= 16'b0000111111111000;
		sprite_9[ 9] <= 16'b0000000000011000;
		sprite_9[10] <= 16'b0000000000011000;
		sprite_9[11] <= 16'b0001100000011000;
		sprite_9[12] <= 16'b0001100000011000;
		sprite_9[13] <= 16'b0000111111110000;
		sprite_9[14] <= 16'b0000011111100000;
		sprite_9[15] <= 16'b0000000000000000;//9
		
		arrow_d[ 0]<= 36'b000000000000000000000000000000000000;
		arrow_d[ 1]<= 36'b000000000000111111111111000000000000;
		arrow_d[ 2]<= 36'b000000000000111111111111000000000000;
		arrow_d[ 3]<= 36'b000000000000111111111111000000000000;
		arrow_d[ 4]<= 36'b000000000000111111111111000000000000;
		arrow_d[ 5]<= 36'b000000000000111111111111000000000000;
		arrow_d[ 6]<= 36'b000000000000111111111111000000000000;
		arrow_d[ 7]<= 36'b000000000000111111111111000000000000;
		arrow_d[ 8]<= 36'b000000000000111111111111000000000000;
		arrow_d[ 9]<= 36'b000000000000111111111111000000000000;
		arrow_d[10]<= 36'b000000000000111111111111000000000000;
		arrow_d[11]<= 36'b000000000000111111111111000000000000;
		arrow_d[12]<= 36'b000000000000111111111111000000000000;
		arrow_d[13]<= 36'b000000000000111111111111000000000000;
		arrow_d[14]<= 36'b000000000000111111111111000000000000;
		arrow_d[15]<= 36'b000000000000111111111111000000000000;
		arrow_d[16]<= 36'b000000000000111111111111000000000000;
		arrow_d[17]<= 36'b000000000000111111111111000000000000;
		arrow_d[18]<= 36'b011111111111111111111111111111111110;
		arrow_d[19]<= 36'b001111111111111111111111111111111100;
		arrow_d[20]<= 36'b000111111111111111111111111111111000;
		arrow_d[21]<= 36'b000011111111111111111111111111110000;
		arrow_d[22]<= 36'b000001111111111111111111111111100000;
		arrow_d[23]<= 36'b000000111111111111111111111111000000;
		arrow_d[24]<= 36'b000000011111111111111111111110000000;
		arrow_d[25]<= 36'b000000001111111111111111111000000000;
		arrow_d[26]<= 36'b000000000111111111111111111000000000;
		arrow_d[27]<= 36'b000000000011111111111111110000000000;
		arrow_d[28]<= 36'b000000000001111111111111100000000000;
		arrow_d[29]<= 36'b000000000000111111111111000000000000;
		arrow_d[30]<= 36'b000000000000011111111110000000000000;
		arrow_d[31]<= 36'b000000000000001111111100000000000000;
		arrow_d[32]<= 36'b000000000000000111111000000000000000;
		arrow_d[33]<= 36'b000000000000000011110000000000000000;
		arrow_d[34]<= 36'b000000000000000001100000000000000000;
		arrow_d[35]<= 36'b000000000000000000000000000000000000;//arrow to down

		arrow_l[ 0]<= 36'b000000000000000000000000000000000000;
		arrow_l[ 1]<= 36'b000000000000000001000000000000000000;
		arrow_l[ 2]<= 36'b000000000000000011000000000000000000;
		arrow_l[ 3]<= 36'b000000000000000111000000000000000000;
		arrow_l[ 4]<= 36'b000000000000001111000000000000000000;
		arrow_l[ 5]<= 36'b000000000000011111000000000000000000;
		arrow_l[ 6]<= 36'b000000000000111111000000000000000000;
		arrow_l[ 7]<= 36'b000000000001111111000000000000000000;
		arrow_l[ 8]<= 36'b000000000011111111000000000000000000;
		arrow_l[ 9]<= 36'b000000000111111111000000000000000000;
		arrow_l[10]<= 36'b000000001111111111000000000000000000;
		arrow_l[11]<= 36'b000000011111111111000000000000000000;
		arrow_l[12]<= 36'b000000111111111111000000000000000000;
		arrow_l[13]<= 36'b000001111111111111111111111111111110;
		arrow_l[14]<= 36'b000011111111111111111111111111111110;
		arrow_l[15]<= 36'b000111111111111111111111111111111110;
		arrow_l[16]<= 36'b001111111111111111111111111111111110;
		arrow_l[17]<= 36'b011111111111111111111111111111111110;
		arrow_l[18]<= 36'b011111111111111111111111111111111110;
		arrow_l[19]<= 36'b001111111111111111111111111111111110;
		arrow_l[20]<= 36'b000111111111111111111111111111111110;
		arrow_l[21]<= 36'b000011111111111111111111111111111110;
		arrow_l[22]<= 36'b000001111111111111111111111111111110;
		arrow_l[23]<= 36'b000000111111111111111111111111111110;
		arrow_l[24]<= 36'b000000011111111111111111111111111110;
		arrow_l[25]<= 36'b000000001111111111000000000000000000;
		arrow_l[26]<= 36'b000000000111111111000000000000000000;
		arrow_l[27]<= 36'b000000000011111111000000000000000000;
		arrow_l[28]<= 36'b000000000001111111000000000000000000;
		arrow_l[29]<= 36'b000000000000111111000000000000000000;
		arrow_l[30]<= 36'b000000000000011111000000000000000000;
		arrow_l[31]<= 36'b000000000000001111000000000000000000;
		arrow_l[32]<= 36'b000000000000000111000000000000000000;
		arrow_l[33]<= 36'b000000000000000011000000000000000000;
		arrow_l[34]<= 36'b000000000000000001000000000000000000;
		arrow_l[35]<= 36'b000000000000000000000000000000000000;//arrow to left

		arrow_r[ 0]<= 36'b000000000000000000000000000000000000;
		arrow_r[ 1]<= 36'b000000000000000000100000000000000000;
		arrow_r[ 2]<= 36'b000000000000000000110000000000000000;
		arrow_r[ 3]<= 36'b000000000000000000111000000000000000;
		arrow_r[ 4]<= 36'b000000000000000000111100000000000000;
		arrow_r[ 5]<= 36'b000000000000000000111110000000000000;
		arrow_r[ 6]<= 36'b000000000000000000111111000000000000;
		arrow_r[ 7]<= 36'b000000000000000000111111100000000000;
		arrow_r[ 8]<= 36'b000000000000000000111111110000000000;
		arrow_r[ 9]<= 36'b000000000000000000111111111000000000;
		arrow_r[10]<= 36'b000000000000000000111111111100000000;
		arrow_r[11]<= 36'b000000000000000000111111111110000000;
		arrow_r[12]<= 36'b000000000000000000111111111111000000;
		arrow_r[13]<= 36'b011111111111111111111111111111100000;
		arrow_r[14]<= 36'b011111111111111111111111111111110000;
		arrow_r[15]<= 36'b011111111111111111111111111111111000;
		arrow_r[16]<= 36'b011111111111111111111111111111111100;
		arrow_r[17]<= 36'b011111111111111111111111111111111110;
		arrow_r[18]<= 36'b011111111111111111111111111111111110;
		arrow_r[19]<= 36'b011111111111111111111111111111111100;
		arrow_r[20]<= 36'b011111111111111111111111111111111000;
		arrow_r[21]<= 36'b011111111111111111111111111111110000;
		arrow_r[22]<= 36'b011111111111111111111111111111100000;
		arrow_r[23]<= 36'b011111111111111111111111111111000000;
		arrow_r[24]<= 36'b011111111111111111111111111110000000;
		arrow_r[25]<= 36'b000000000000000000111111111100000000;
		arrow_r[26]<= 36'b000000000000000000111111111000000000;
		arrow_r[27]<= 36'b000000000000000000111111110000000000;
		arrow_r[28]<= 36'b000000000000000000111111100000000000;
		arrow_r[29]<= 36'b000000000000000000111111000000000000;
		arrow_r[30]<= 36'b000000000000000000111110000000000000;
		arrow_r[31]<= 36'b000000000000000000111100000000000000;
		arrow_r[32]<= 36'b000000000000000000111000000000000000;
		arrow_r[33]<= 36'b000000000000000000110000000000000000;
		arrow_r[34]<= 36'b000000000000000000100000000000000000;
		arrow_r[35]<= 36'b000000000000000000000000000000000000;//arrow to right

		arrow_u[ 0]<= 36'b000000000000000000000000000000000000;
		arrow_u[ 1]<= 36'b000000000000000001100000000000000000;
		arrow_u[ 2]<= 36'b000000000000000011110000000000000000;
		arrow_u[ 3]<= 36'b000000000000000111111000000000000000;
		arrow_u[ 4]<= 36'b000000000000001111111100000000000000;
		arrow_u[ 5]<= 36'b000000000000011111111110000000000000;
		arrow_u[ 6]<= 36'b000000000000111111111111000000000000;
		arrow_u[ 7]<= 36'b000000000001111111111111100000000000;
		arrow_u[ 8]<= 36'b000000000011111111111111110000000000;
		arrow_u[ 9]<= 36'b000000000111111111111111111000000000;
		arrow_u[10]<= 36'b000000001111111111111111111100000000;
		arrow_u[11]<= 36'b000000011111111111111111111110000000;
		arrow_u[12]<= 36'b000000111111111111111111111111000000;
		arrow_u[13]<= 36'b000001111111111111111111111111100000;
		arrow_u[14]<= 36'b000011111111111111111111111111110000;
		arrow_u[15]<= 36'b000111111111111111111111111111111000;
		arrow_u[16]<= 36'b001111111111111111111111111111111100;
		arrow_u[17]<= 36'b011111111111111111111111111111111110;
		arrow_u[18]<= 36'b000000000000111111111111000000000000;
		arrow_u[19]<= 36'b000000000000111111111111000000000000;
		arrow_u[20]<= 36'b000000000000111111111111000000000000;
		arrow_u[21]<= 36'b000000000000111111111111000000000000;
		arrow_u[22]<= 36'b000000000000111111111111000000000000;
		arrow_u[23]<= 36'b000000000000111111111111000000000000;
		arrow_u[24]<= 36'b000000000000111111111111000000000000;
		arrow_u[25]<= 36'b000000000000111111111111000000000000;
		arrow_u[26]<= 36'b000000000000111111111111000000000000;
		arrow_u[27]<= 36'b000000000000111111111111000000000000;
		arrow_u[28]<= 36'b000000000000111111111111000000000000;
		arrow_u[29]<= 36'b000000000000111111111111000000000000;
		arrow_u[30]<= 36'b000000000000111111111111000000000000;
		arrow_u[31]<= 36'b000000000000111111111111000000000000;
		arrow_u[32]<= 36'b000000000000111111111111000000000000;
		arrow_u[33]<= 36'b000000000000111111111111000000000000;
		arrow_u[34]<= 36'b000000000000111111111111000000000000;
		arrow_u[35]<= 36'b000000000000000000000000000000000000;//arrow to up

	end
	
	//SCORE & ERROR Points, also display items 
	always @(posedge clk)begin
    ones = scoretwo%10;
    tens = (scoretwo/10)%10;
    hundreds = (scoretwo/100)%10;
	 thousands = (scoretwo/1000)%10;
	
	 w_ones = wrongs%10;
	 w_tens = (wrongs/10)%10;
	  
	if (!blank) begin
				//letter1: S
				if (((hcount >= 10) && (hcount <= 10+15)) && ((vcount >= 10) && (vcount <= 10+15)))begin
					letter1_row <= sprite_S[vcount - 10];
					if (letter1_row[10+15-hcount])
						letter1_on <= 1;
					else
						letter1_on <= 0;
				end
				//letter2: C
				else if (((hcount >= 30) && (hcount <= 30+15)) && ((vcount >= 10) && (vcount <= 10+15)))begin
					letter2_row <= sprite_C[vcount - 10];
					if (letter2_row[30+15-hcount])
						letter2_on <= 1;
					else
						letter2_on <= 0;
				end
				//letter3: O
				else if (((hcount >= 50) && (hcount <= 50+15)) && ((vcount >= 10) && (vcount <= 10+15)))begin
					letter3_row <= sprite_O[vcount - 10];
					if (letter3_row[50+15-hcount])
						letter3_on <= 1;
					else
						letter3_on <= 0;
				end
				//letter4: R
				else if (((hcount >= 70) && (hcount <= 70+15)) && ((vcount >= 10) && (vcount <= 10+15)))begin
					letter4_row <= sprite_R[vcount - 10];
					if (letter4_row[70+15-hcount])
						letter4_on <= 1;
					else
						letter4_on <= 0;
				end
				//letter5: E
				else if (((hcount >= 90) && (hcount <= 90+15)) && ((vcount >= 10) && (vcount <= 10+15)))begin
					letter5_row <= sprite_E[vcount - 10];
					if (letter5_row[90+15-hcount])
						letter5_on <= 1;
					else
						letter5_on <= 0;
				end
				//letter6: :
				else if (((hcount >= 110) && (hcount <= 110+15)) && ((vcount >= 10) && (vcount <= 10+15)))begin
					letter6_row <= sprite_colon[vcount - 10];
					if (letter6_row[110+15-hcount])
						letter6_on <= 1;
					else
						letter6_on <= 0;
				end		
            //digit 0
				else if (((hcount >= 130) && (hcount <= 130+15)) && ((vcount >= 10) && (vcount <= 10+15)))
				begin
						case(thousands)
				0: digit_0_row <= sprite_0[vcount - 10];
				1: digit_0_row <= sprite_1[vcount - 10];
				2: digit_0_row <= sprite_2[vcount - 10];
				3: digit_0_row <= sprite_3[vcount - 10];
				4: digit_0_row <= sprite_4[vcount - 10];
				5: digit_0_row <= sprite_5[vcount - 10];
				6: digit_0_row <= sprite_6[vcount - 10];
				7: digit_0_row <= sprite_7[vcount - 10];
				8: digit_0_row <= sprite_8[vcount - 10];
				9: digit_0_row <= sprite_9[vcount - 10];
				default: digit_0_row <= sprite_0[vcount - 10];
						endcase
						if (digit_0_row[130+15-hcount])
							digit_0_on <= 1;
						else
							digit_0_on <= 0;		
				end						
            //digit 1
				else if (((hcount >= 150) && (hcount <= 150+15)) && ((vcount >= 10) && (vcount <= 10+15)))
				begin
						case(hundreds)
				0: digit_1_row <= sprite_0[vcount - 10];
				1: digit_1_row <= sprite_1[vcount - 10];
				2: digit_1_row <= sprite_2[vcount - 10];
				3: digit_1_row <= sprite_3[vcount - 10];
				4: digit_1_row <= sprite_4[vcount - 10];
				5: digit_1_row <= sprite_5[vcount - 10];
				6: digit_1_row <= sprite_6[vcount - 10];
				7: digit_1_row <= sprite_7[vcount - 10];
				8: digit_1_row <= sprite_8[vcount - 10];
				9: digit_1_row <= sprite_9[vcount - 10];
				default: digit_1_row <= sprite_0[vcount - 10];
                  endcase
					if (digit_1_row[150+15-hcount])
						digit_1_on <= 1;
					else
						digit_1_on <= 0;
				end	
				//digit 2
				else if (((hcount >= 170) && (hcount <= 170+15)) && ((vcount >= 10) && (vcount <= 10+15)))
				begin
						case(tens)
				0: digit_2_row <= sprite_0[vcount - 10];
				1: digit_2_row <= sprite_1[vcount - 10];
				2: digit_2_row <= sprite_2[vcount - 10];
				3: digit_2_row <= sprite_3[vcount - 10];
				4: digit_2_row <= sprite_4[vcount - 10];
				5: digit_2_row <= sprite_5[vcount - 10];
				6: digit_2_row <= sprite_6[vcount - 10];
				7: digit_2_row <= sprite_7[vcount - 10];
				8: digit_2_row <= sprite_8[vcount - 10];
				9: digit_2_row <= sprite_9[vcount - 10];
				default: digit_2_row <= sprite_0[vcount - 10];
                endcase
					if (digit_2_row[170+15-hcount])
						digit_2_on <= 1;
					else
						digit_2_on <= 0;
				end

				//digit 21
				else if (((hcount >= 190) && (hcount <= 190+15)) && ((vcount >= 10) && (vcount <= 10+15)))
				begin
						case(ones)
				0: digit_21_row <= sprite_0[vcount - 10];
				1: digit_21_row <= sprite_1[vcount - 10];
				2: digit_21_row <= sprite_2[vcount - 10];
				3: digit_21_row <= sprite_3[vcount - 10];
				4: digit_21_row <= sprite_4[vcount - 10];
				5: digit_21_row <= sprite_5[vcount - 10];
				6: digit_21_row <= sprite_6[vcount - 10];
				7: digit_21_row <= sprite_7[vcount - 10];
				8: digit_21_row <= sprite_8[vcount - 10];
				9: digit_21_row <= sprite_9[vcount - 10];
				default: digit_21_row <= sprite_0[vcount - 10];
                endcase
					if (digit_21_row[190+15-hcount])
						digit_21_on <= 1;
					else
						digit_21_on <= 0;
				end
				
				//letter7: E
				else if (((hcount >= 400) && (hcount <= 400+15)) && ((vcount >= 10) && (vcount <= 10+15)))begin
					letter7_row <= sprite_E[vcount - 10];
					if (letter7_row[400+15-hcount])
						letter7_on <= 1;
					else
						letter7_on <= 0;
				end
				//letter8: R
				else if (((hcount >= 420) && (hcount <= 420+15)) && ((vcount >= 10) && (vcount <= 10+15)))begin
					letter8_row <= sprite_R[vcount - 10];
					if (letter8_row[420+15-hcount])
						letter8_on <= 1;
					else
						letter8_on <= 0;
				end
				//letter9: R
				else if (((hcount >= 440) && (hcount <= 440+15)) && ((vcount >= 10) && (vcount <= 10+15)))begin
					letter9_row <= sprite_R[vcount - 10];
					if (letter9_row[440+15-hcount])
						letter9_on <= 1;
					else
						letter9_on <= 0;
				end
				//letter10: O
				else if (((hcount >= 460) && (hcount <= 460+15)) && ((vcount >= 10) && (vcount <= 10+15)))begin
					letter10_row <= sprite_O[vcount - 10];
					if (letter10_row[460+15-hcount])
						letter10_on <= 1;
					else
						letter10_on <= 0;
				end
				//letter11: R
				else if (((hcount >= 480) && (hcount <= 480+15)) && ((vcount >= 10) && (vcount <= 10+15)))begin
					letter11_row <= sprite_R[vcount - 10];
					if (letter11_row[480+15-hcount])
						letter11_on <= 1;
					else
						letter11_on <= 0;
				end
				//letter12: :
				else if (((hcount >= 500) && (hcount <= 500+15)) && ((vcount >= 10) && (vcount <= 10+15)))begin
					letter12_row <= sprite_colon[vcount - 10];
					if (letter12_row[500+15-hcount])
						letter12_on <= 1;
					else
						letter12_on <= 0;
				end	
            //digit 5
				else if (((hcount >= 560) && (hcount <= 560+15)) && ((vcount >= 10) && (vcount <= 10+15)))
				begin
						case(w_ones)
				0: digit_5_row <= sprite_0[vcount - 10];
				1: digit_5_row <= sprite_1[vcount - 10];
				2: digit_5_row <= sprite_2[vcount - 10];
				3: digit_5_row <= sprite_3[vcount - 10];
				4: digit_5_row <= sprite_4[vcount - 10];
				5: digit_5_row <= sprite_5[vcount - 10];
				6: digit_5_row <= sprite_6[vcount - 10];
				7: digit_5_row <= sprite_7[vcount - 10];
				8: digit_5_row <= sprite_8[vcount - 10];
				9: digit_5_row <= sprite_9[vcount - 10];
				default: digit_5_row <= sprite_0[vcount - 10];
                endcase
					if (digit_5_row[560+15-hcount])
						digit_5_on <= 1;
					else
						digit_5_on <= 0;
				end
				//digit 4 : Always on
				else if (((hcount >= 540) && (hcount <= 540+15)) && ((vcount >= 10) && (vcount <= 10+15)))
				begin
						case(w_tens)
				0: digit_4_row <= sprite_0[vcount - 10];
				1: digit_4_row <= sprite_1[vcount - 10];
				2: digit_4_row <= sprite_2[vcount - 10];
				3: digit_4_row <= sprite_3[vcount - 10];
				4: digit_4_row <= sprite_4[vcount - 10];
				5: digit_4_row <= sprite_5[vcount - 10];
				6: digit_4_row <= sprite_6[vcount - 10];
				7: digit_4_row <= sprite_7[vcount - 10];
				8: digit_4_row <= sprite_8[vcount - 10];
				9: digit_4_row <= sprite_9[vcount - 10];
				default: digit_4_row <= sprite_0[vcount - 10];
                endcase
					if (digit_4_row[540+15-hcount])
						digit_4_on <= 1;
					else
						digit_4_on <= 0;
				end
/*				else if (((hcount >= 540) && (hcount <= 540+15)) && ((vcount >= 10) && (vcount <= 10+15)))
				begin
				    digit_4_row <= sprite_0[vcount - 10];
					 if (digit_4_row[540+15-hcount])
						digit_4_on <= 1;
					 else
						digit_4_on <= 0;
				end*/
				//digit 3 : Always on
				else if (((hcount >= 520) && (hcount <= 520+15)) && ((vcount >= 10) && (vcount <= 10+15)))
				begin
				    digit_3_row <= sprite_0[vcount - 10];
					 if (digit_3_row[520+15-hcount])
						digit_3_on <= 1;
					 else
						digit_3_on <= 0;
				end
//First arrow line from the left			
         else if (((hcount >= 67) && (hcount <= 67+35)) && ((vcount >= M1-35) && (vcount <= M1)))begin
		    figure11_1 <=arrow_l[vcount - (M1-35)];
			if (figure11_1[67+35-hcount])
			    figure1_1 <= 1;
			else
			    figure1_1 <= 0;	
			end	 
         else if (((hcount >= 67) && (hcount <= 67+35)) && ((vcount >= M2-35) && (vcount <= M2)))begin
		    figure11_2 <=arrow_l[vcount - (M2-35)];
			if (figure11_2[67+35-hcount])
			    figure1_2 <= 1;
			else
			    figure1_2 <= 0;
			end
         else if (((hcount >= 67) && (hcount <= 67+35)) && ((vcount >= M3-35) && (vcount <= M3)))begin
		    figure11_3 <=arrow_l[vcount - (M3-35)];
			if (figure11_3[67+35-hcount])
			    figure1_3 <= 1;
			else
			    figure1_3 <= 0;
		   end
         else if (((hcount >= 67) && (hcount <= 67+35)) && ((vcount >= M4-35) && (vcount <= M4)))begin
		    figure11_4 <=arrow_l[vcount - (M4-35)];
			if (figure11_4[67+35-hcount])
			    figure1_4 <= 1;
			else
			    figure1_4 <= 0;
			end
			
			else if (((hcount >= 67) && (hcount <= 67+35)) && ((vcount >= M5-35) && (vcount <= M5)))begin
		    figure11_5 <=arrow_l[vcount - (M5-35)];
			if (figure11_5[67+35-hcount])
			    figure1_5 <= 1;
			else
			    figure1_5 <= 0;	
			end	 
         else if (((hcount >= 67) && (hcount <= 67+35)) && ((vcount >= M6-35) && (vcount <= M6)))begin
		    figure11_6 <=arrow_l[vcount - (M6-35)];
			if (figure11_6[67+35-hcount])
			    figure1_6 <= 1;
			else
			    figure1_6 <= 0;
			end
         else if (((hcount >= 67) && (hcount <= 67+35)) && ((vcount >= M7-35) && (vcount <= M7)))begin
		    figure11_7 <=arrow_l[vcount - (M7-35)];
			if (figure11_7[67+35-hcount])
			    figure1_7 <= 1;
			else
			    figure1_7 <= 0;
		   end
         else if (((hcount >= 67) && (hcount <= 67+35)) && ((vcount >= M8-35) && (vcount <= M8)))begin
		    figure11_8 <=arrow_l[vcount - (M8-35)];
			if (figure11_8	[67+35-hcount])
			    figure1_8 <= 1;
			else
			    figure1_8 <= 0;
			end
			
			else if (((hcount >= 67) && (hcount <= 67+35)) && ((vcount >= M9-35) && (vcount <= M9)))begin
		    figure11_9 <=arrow_l[vcount - (M9-35)];
			if (figure11_9[67+35-hcount])
			    figure1_9 <= 1;
			else
			    figure1_9 <= 0;	
			end	 
         else if (((hcount >= 67) && (hcount <= 67+35)) && ((vcount >= M10-35) && (vcount <= M10)))begin
		    figure11_10 <=arrow_l[vcount - (M10-35)];
			if (figure11_10[67+35-hcount])
			    figure1_10 <= 1;
			else
			    figure1_10 <= 0;
			end
         else if (((hcount >= 67) && (hcount <= 67+35)) && ((vcount >= M11-35) && (vcount <= M11)))begin
		    figure11_11 <=arrow_l[vcount - (M11-35)];
			if (figure11_11[67+35-hcount])
			    figure1_11 <= 1;
			else
			    figure1_11 <= 0;
		   end
         else if (((hcount >= 67) && (hcount <= 67+35)) && ((vcount >= M12-35) && (vcount <= M12)))begin
		    figure11_12 <=arrow_l[vcount - (M12-35)];
			if (figure11_12[67+35-hcount])
			    figure1_12 <= 1;
			else
			    figure1_12 <= 0;
			end
			
			else if (((hcount >= 67) && (hcount <= 67+35)) && ((vcount >= M13-35) && (vcount <= M13)))begin
		    figure11_13 <=arrow_l[vcount - (M13-35)];
			if (figure11_13[67+35-hcount])
			    figure1_13 <= 1;
			else
			    figure1_13 <= 0;	
			end	 
         else if (((hcount >= 67) && (hcount <= 67+35)) && ((vcount >= M14-35) && (vcount <= M14)))begin
		    figure11_14 <=arrow_l[vcount - (M14-35)];
			if (figure11_14[67+35-hcount])
			    figure1_14 <= 1;
			else
			    figure1_14 <= 0;
			end
         else if (((hcount >= 67) && (hcount <= 67+35)) && ((vcount >= M15-35) && (vcount <= M15)))begin
		    figure11_15 <=arrow_l[vcount - (M15-35)];
			if (figure11_15[67+35-hcount])
			    figure1_15 <= 1;
			else
			    figure1_15 <= 0;
		   end
         else if (((hcount >= 67) && (hcount <= 67+35)) && ((vcount >= M16-35) && (vcount <= M16)))begin
		    figure11_16 <=arrow_l[vcount - (M16-35)];
			if (figure11_16[67+35-hcount])
			    figure1_16 <= 1;
			else
			    figure1_16 <= 0;
			end
			
//Second arrow line from the left			
         else if (((hcount >= 210) && (hcount <= 210+35)) && ((vcount >= M1-35) && (vcount <= M1)))begin
		    figure22_1 <=arrow_u[vcount - (M1-35)];
			if (figure22_1[210+35-hcount])
			    figure2_1 <= 1;
			else
			    figure2_1 <= 0;	
			end	 
         else if (((hcount >= 210) && (hcount <= 210+35)) && ((vcount >= M2-35) && (vcount <= M2)))begin
		    figure22_2 <=arrow_u[vcount - (M2-35)];
			if (figure22_2[210+35-hcount])
			    figure2_2 <= 1;
			else
			    figure2_2 <= 0;
			end
         else if (((hcount >= 210) && (hcount <= 210+35)) && ((vcount >= M3-35) && (vcount <= M3)))begin
		    figure22_3 <=arrow_u[vcount - (M3-35)];
			if (figure22_3[210+35-hcount])
			    figure2_3 <= 1;
			else
			    figure2_3 <= 0;
		   end
         else if (((hcount >= 210) && (hcount <= 210+35)) && ((vcount >= M4-35) && (vcount <= M4)))begin
		    figure22_4 <=arrow_u[vcount - (M4-35)];
			if (figure22_4[210+35-hcount])
			    figure2_4 <= 1;
			else
			    figure2_4 <= 0;
			end
			
			else if (((hcount >= 210) && (hcount <= 210+35)) && ((vcount >= M5-35) && (vcount <= M5)))begin
		    figure22_5 <=arrow_u[vcount - (M5-35)];
			if (figure22_5[210+35-hcount])
			    figure2_5 <= 1;
			else
			    figure2_5 <= 0;	
			end	 
         else if (((hcount >= 210) && (hcount <= 210+35)) && ((vcount >= M6-35) && (vcount <= M6)))begin
		    figure22_6 <=arrow_u[vcount - (M6-35)];
			if (figure22_6[210+35-hcount])
			    figure2_6 <= 1;
			else
			    figure2_6 <= 0;
			end
         else if (((hcount >= 210) && (hcount <= 210+35)) && ((vcount >= M7-35) && (vcount <= M7)))begin
		    figure22_7 <=arrow_u[vcount - (M7-35)];
			if (figure22_7[210+35-hcount])
			    figure2_7 <= 1;
			else
			    figure2_7 <= 0;
		   end
         else if (((hcount >= 210) && (hcount <= 210+35)) && ((vcount >= M8-35) && (vcount <= M8)))begin
		    figure22_8 <=arrow_u[vcount - (M8-35)];
			if (figure22_8	[210+35-hcount])
			    figure2_8 <= 1;
			else
			    figure2_8 <= 0;
			end
			
			else if (((hcount >= 210) && (hcount <= 210+35)) && ((vcount >= M9-35) && (vcount <= M9)))begin
		    figure22_9 <=arrow_u[vcount - (M9-35)];
			if (figure22_9[210+35-hcount])
			    figure2_9 <= 1;
			else
			    figure2_9 <= 0;	
			end	 
         else if (((hcount >= 210) && (hcount <= 210+35)) && ((vcount >= M10-35) && (vcount <= M10)))begin
		    figure22_10 <=arrow_u[vcount - (M10-35)];
			if (figure22_10[210+35-hcount])
			    figure2_10 <= 1;
			else
			    figure2_10 <= 0;
			end
         else if (((hcount >= 210) && (hcount <= 210+35)) && ((vcount >= M11-35) && (vcount <= M11)))begin
		    figure22_11 <=arrow_u[vcount - (M11-35)];
			if (figure22_11[210+35-hcount])
			    figure2_11 <= 1;
			else
			    figure2_11 <= 0;
		   end
         else if (((hcount >= 210) && (hcount <= 210+35)) && ((vcount >= M12-35) && (vcount <= M12)))begin
		    figure22_12 <=arrow_u[vcount - (M12-35)];
			if (figure22_12[210+35-hcount])
			    figure2_12 <= 1;
			else
			    figure2_12 <= 0;
			end
			
			else if (((hcount >= 210) && (hcount <= 210+35)) && ((vcount >= M13-35) && (vcount <= M13)))begin
		    figure22_13 <=arrow_u[vcount - (M13-35)];
			if (figure22_13[210+35-hcount])
			    figure2_13 <= 1;
			else
			    figure2_13 <= 0;	
			end	 
         else if (((hcount >= 210) && (hcount <= 210+35)) && ((vcount >= M14-35) && (vcount <= M14)))begin
		    figure22_14 <=arrow_u[vcount - (M14-35)];
			if (figure22_14[210+35-hcount])
			    figure2_14 <= 1;
			else
			    figure2_14 <= 0;
			end
         else if (((hcount >= 210) && (hcount <= 210+35)) && ((vcount >= M15-35) && (vcount <= M15)))begin
		    figure22_15 <=arrow_u[vcount - (M15-35)];
			if (figure22_15[210+35-hcount])
			    figure2_15 <= 1;
			else
			    figure2_15 <= 0;
		   end
         else if (((hcount >= 210) && (hcount <= 210+35)) && ((vcount >= M16-35) && (vcount <= M16)))begin
		    figure22_16 <=arrow_u[vcount - (M16-35)];
			if (figure22_16[210+35-hcount])
			    figure2_16 <= 1;
			else
			    figure2_16 <= 0;
			end
			
//Third arrow line from the left			
         else if (((hcount >= 353) && (hcount <= 353+35)) && ((vcount >= M1-35) && (vcount <= M1)))begin
		    figure33_1 <=arrow_d[vcount - (M1-35)];
			if (figure33_1[353+35-hcount])
			    figure3_1 <= 1;
			else
			    figure3_1 <= 0;	
			end	 
         else if (((hcount >= 353) && (hcount <= 353+35)) && ((vcount >= M2-35) && (vcount <= M2)))begin
		    figure33_2 <=arrow_d[vcount - (M2-35)];
			if (figure33_2[353+35-hcount])
			    figure3_2 <= 1;
			else
			    figure3_2 <= 0;
			end
         else if (((hcount >= 353) && (hcount <= 353+35)) && ((vcount >= M3-35) && (vcount <= M3)))begin
		    figure33_3 <=arrow_d[vcount - (M3-35)];
			if (figure33_3[353+35-hcount])
			    figure3_3 <= 1;
			else
			    figure3_3 <= 0;
		   end
         else if (((hcount >= 353) && (hcount <= 353+35)) && ((vcount >= M4-35) && (vcount <= M4)))begin
		    figure33_4 <=arrow_d[vcount - (M4-35)];
			if (figure33_4[353+35-hcount])
			    figure3_4 <= 1;
			else
			    figure3_4 <= 0;
			end
			
			else if (((hcount >= 353) && (hcount <= 353+35)) && ((vcount >= M5-35) && (vcount <= M5)))begin
		    figure33_5 <=arrow_d[vcount - (M5-35)];
			if (figure33_5[353+35-hcount])
			    figure3_5 <= 1;
			else
			    figure3_5 <= 0;	
			end	 
         else if (((hcount >= 353) && (hcount <= 353+35)) && ((vcount >= M6-35) && (vcount <= M6)))begin
		    figure33_6 <=arrow_d[vcount - (M6-35)];
			if (figure33_6[353+35-hcount])
			    figure3_6 <= 1;
			else
			    figure3_6 <= 0;
			end
         else if (((hcount >= 353) && (hcount <= 353+35)) && ((vcount >= M7-35) && (vcount <= M7)))begin
		    figure33_7 <=arrow_d[vcount - (M7-35)];
			if (figure33_7[353+35-hcount])
			    figure3_7 <= 1;
			else
			    figure3_7 <= 0;
		   end
         else if (((hcount >= 353) && (hcount <= 353+35)) && ((vcount >= M8-35) && (vcount <= M8)))begin
		    figure33_8 <=arrow_d[vcount - (M8-35)];
			if (figure33_8	[353+35-hcount])
			    figure3_8 <= 1;
			else
			    figure3_8 <= 0;
			end
			
			else if (((hcount >= 353) && (hcount <= 353+35)) && ((vcount >= M9-35) && (vcount <= M9)))begin
		    figure33_9 <=arrow_d[vcount - (M9-35)];
			if (figure33_9[353+35-hcount])
			    figure3_9 <= 1;
			else
			    figure3_9 <= 0;	
			end	 
         else if (((hcount >= 353) && (hcount <= 353+35)) && ((vcount >= M10-35) && (vcount <= M10)))begin
		    figure33_10 <=arrow_d[vcount - (M10-35)];
			if (figure33_10[353+35-hcount])
			    figure3_10 <= 1;
			else
			    figure3_10 <= 0;
			end
         else if (((hcount >= 353) && (hcount <= 353+35)) && ((vcount >= M11-35) && (vcount <= M11)))begin
		    figure33_11 <=arrow_d[vcount - (M11-35)];
			if (figure33_11[353+35-hcount])
			    figure3_11 <= 1;
			else
			    figure3_11 <= 0;
		   end
         else if (((hcount >= 353) && (hcount <= 353+35)) && ((vcount >= M12-35) && (vcount <= M12)))begin
		    figure33_12 <=arrow_d[vcount - (M12-35)];
			if (figure33_12[353+35-hcount])
			    figure3_12 <= 1;
			else
			    figure3_12 <= 0;
			end
			
			else if (((hcount >= 353) && (hcount <= 353+35)) && ((vcount >= M13-35) && (vcount <= M13)))begin
		    figure33_13 <=arrow_d[vcount - (M13-35)];
			if (figure33_13[353+35-hcount])
			    figure3_13 <= 1;
			else
			    figure3_13 <= 0;	
			end	 
         else if (((hcount >= 353) && (hcount <= 353+35)) && ((vcount >= M14-35) && (vcount <= M14)))begin
		    figure33_14 <=arrow_d[vcount - (M14-35)];
			if (figure33_14[353+35-hcount])
			    figure3_14 <= 1;
			else
			    figure3_14 <= 0;
			end
         else if (((hcount >= 353) && (hcount <= 353+35)) && ((vcount >= M15-35) && (vcount <= M15)))begin
		    figure33_15 <=arrow_d[vcount - (M15-35)];
			if (figure33_15[353+35-hcount])
			    figure3_15 <= 1;
			else
			    figure3_15 <= 0;
		   end
         else if (((hcount >= 353) && (hcount <= 353+35)) && ((vcount >= M16-35) && (vcount <= M16)))begin
		    figure33_16 <=arrow_d[vcount - (M16-35)];
			if (figure33_16[353+35-hcount])
			    figure3_16 <= 1;
			else
			    figure3_16 <= 0;
			end

//Fourth arrow line from the left			
         else if (((hcount >= 496) && (hcount <= 496+35)) && ((vcount >= M1-35) && (vcount <= M1)))begin
		    figure44_1 <=arrow_r[vcount - (M1-35)];
			if (figure44_1[496+35-hcount])
			    figure4_1 <= 1;
			else
			    figure4_1 <= 0;	
			end	 
         else if (((hcount >= 496) && (hcount <= 496+35)) && ((vcount >= M2-35) && (vcount <= M2)))begin
		    figure44_2 <=arrow_r[vcount - (M2-35)];
			if (figure44_2[496+35-hcount])
			    figure4_2 <= 1;
			else
			    figure4_2 <= 0;
			end
         else if (((hcount >= 496) && (hcount <= 496+35)) && ((vcount >= M3-35) && (vcount <= M3)))begin
		    figure44_3 <=arrow_r[vcount - (M3-35)];
			if (figure44_3[496+35-hcount])
			    figure4_3 <= 1;
			else
			    figure4_3 <= 0;
		   end
         else if (((hcount >= 496) && (hcount <= 496+35)) && ((vcount >= M4-35) && (vcount <= M4)))begin
		    figure44_4 <=arrow_r[vcount - (M4-35)];
			if (figure44_4[496+35-hcount])
			    figure4_4 <= 1;
			else
			    figure4_4 <= 0;
			end
			
			else if (((hcount >= 496) && (hcount <= 496+35)) && ((vcount >= M5-35) && (vcount <= M5)))begin
		    figure44_5 <=arrow_r[vcount - (M5-35)];
			if (figure44_5[496+35-hcount])
			    figure4_5 <= 1;
			else
			    figure4_5 <= 0;	
			end	 
         else if (((hcount >= 496) && (hcount <= 496+35)) && ((vcount >= M6-35) && (vcount <= M6)))begin
		    figure44_6 <=arrow_r[vcount - (M6-35)];
			if (figure44_6[496+35-hcount])
			    figure4_6 <= 1;
			else
			    figure4_6 <= 0;
			end
         else if (((hcount >= 496) && (hcount <= 496+35)) && ((vcount >= M7-35) && (vcount <= M7)))begin
		    figure44_7 <=arrow_r[vcount - (M7-35)];
			if (figure44_7[496+35-hcount])
			    figure4_7 <= 1;
			else
			    figure4_7 <= 0;
		   end
         else if (((hcount >= 496) && (hcount <= 496+35)) && ((vcount >= M8-35) && (vcount <= M8)))begin
		    figure44_8 <=arrow_r[vcount - (M8-35)];
			if (figure44_8	[496+35-hcount])
			    figure4_8 <= 1;
			else
			    figure4_8 <= 0;
			end
			
			else if (((hcount >= 496) && (hcount <= 496+35)) && ((vcount >= M9-35) && (vcount <= M9)))begin
		    figure44_9 <=arrow_r[vcount - (M9-35)];
			if (figure44_9[496+35-hcount])
			    figure4_9 <= 1;
			else
			    figure4_9 <= 0;	
			end	 
         else if (((hcount >= 496) && (hcount <= 496+35)) && ((vcount >= M10-35) && (vcount <= M10)))begin
		    figure44_10 <=arrow_r[vcount - (M10-35)];
			if (figure44_10[496+35-hcount])
			    figure4_10 <= 1;
			else
			    figure4_10 <= 0;
			end
         else if (((hcount >= 496) && (hcount <= 496+35)) && ((vcount >= M11-35) && (vcount <= M11)))begin
		    figure44_11 <=arrow_r[vcount - (M11-35)];
			if (figure44_11[496+35-hcount])
			    figure4_11 <= 1;
			else
			    figure4_11 <= 0;
		   end
         else if (((hcount >= 496) && (hcount <= 496+35)) && ((vcount >= M12-35) && (vcount <= M12)))begin
		    figure44_12 <=arrow_r[vcount - (M12-35)];
			if (figure44_12[496+35-hcount])
			    figure4_12 <= 1;
			else
			    figure4_12 <= 0;
			end
			
			else if (((hcount >= 496) && (hcount <= 496+35)) && ((vcount >= M13-35) && (vcount <= M13)))begin
		    figure44_13 <=arrow_r[vcount - (M13-35)];
			if (figure44_13[496+35-hcount])
			    figure4_13 <= 1;
			else
			    figure4_13 <= 0;	
			end	 
         else if (((hcount >= 496) && (hcount <= 496+35)) && ((vcount >= M14-35) && (vcount <= M14)))begin
		    figure44_14 <=arrow_r[vcount - (M14-35)];
			if (figure44_14[496+35-hcount])
			    figure4_14 <= 1;
			else
			    figure4_14 <= 0;
			end
         else if (((hcount >= 496) && (hcount <= 496+35)) && ((vcount >= M15-35) && (vcount <= M15)))begin
		    figure44_15 <=arrow_r[vcount - (M15-35)];
			if (figure44_15[496+35-hcount])
			    figure4_15 <= 1;
			else
			    figure4_15 <= 0;
		   end
         else if (((hcount >= 496) && (hcount <= 496+35)) && ((vcount >= M16-35) && (vcount <= M16)))begin
		    figure44_16 <=arrow_r[vcount - (M16-35)];
			if (figure44_16[496+35-hcount])
			    figure4_16 <= 1;
			else
			    figure4_16 <= 0;
			end

		end
	end

  //block movement & spacing
  always @(posedge o_clk) begin
		 if (reset==1) begin
				figcount = 101'b0;
				start1 = 0;
				start2 = 0;
				start3 = 0;
				start4 = 0;
				start5 = 0;
				start6 = 0;
				start7 = 0;
				start8 = 0;
				start9 = 0;
				start10 = 0;
				start11 = 0;
				start12 = 0;
				start13 = 0;
				start14 = 0;
				start15 = 0;
				start16 = 0;

				M1 = 10'd103;
				M2 = 10'd103;
				M3 = 10'd103;
				M4 = 10'd103;
				M5 = 10'd103;
				M6 = 10'd103;
				M7 = 10'd103;
				M8 = 10'd103;
				M9 = 10'd103;
				M10= 10'd103;
				M11= 10'd103;
				M12= 10'd103;
				M13= 10'd103;
				M14= 10'd103;
				M15= 10'd103;
				M16= 10'd103;
		 end
		 if (M1==463) begin
			  M1 = 103;
		 end
		 if (M2==463) begin
			  M2 = 103;
		 end
		 if (M3==463) begin
			  M3 = 103;
		 end
		 if (M4==463) begin
			  M4 = 103;
		 end
		 if (M5==463) begin
			  M5 = 103;
		 end
		 if (M6==463) begin
			  M6 = 103;
		 end
		 if (M7==463) begin
			  M7 = 103;
		 end
		 if (M8==463) begin
			  M8 = 103;
		 end
		 if (M9==463) begin
			  M9 = 103;
		 end
		 if (M10==463) begin
			  M10 = 103;
		 end
		 if (M11==463) begin
			  M11 = 103;
		 end
		 if (M12==463) begin
			  M12 = 103;
		 end
		 if (M13==463) begin
			  M13 = 103;
		 end
		 if (M14==463) begin
			  M14 = 103;
		 end
		 if (M15==463) begin
			  M15 = 103;
		 end
		 if (M16==463) begin
			  M16 = 103;
		 end
		 
	if(Btn_turbo == 0)begin
		if (figcount > 0 && start1 == 0) begin
			start1 = 1;
		end
		if (figcount > 45 && start2 == 0) begin
			start2 = 1;
		end
		if (figcount > 90 && start3 == 0) begin
			start3 = 1;
		end
		if (figcount > 135 && start4 == 0) begin
			start4 = 1;
		end
		if (figcount > 180 && start5 == 0) begin
			start5 = 1;
		end
		if (figcount > 225 && start6 == 0) begin
			start6 = 1;
		end
		if (figcount > 270 && start7 == 0) begin
			start7 = 1;
		end
		if (figcount > 315 && start8 == 0) begin
			start8 = 1;
		end		

		if (start1 == 1) begin
			M1 = M1 + 1'b1;
		end
		if (start2 == 1) begin
			M2 = M2 + 1'b1;
		end
		if (start3 == 1) begin
			M3 = M3 + 1'b1;
		end
		if (start4 == 1) begin
			M4 = M4 + 1'b1;
		end
		if (start5 == 1) begin
			M5 = M5 + 1'b1;
		end
		if (start6 == 1) begin
			M6 = M6 + 1'b1;
		end
		if (start7 == 1) begin
			M7 = M7 + 1'b1;
		end
		if (start8 == 1) begin
			M8 = M8 + 1'b1;
		end
		figcount = figcount + 1'b1;
	end
	
	else if(Btn_turbo == 1)begin
		if (figcount > 0 && start1 == 0) begin
			start1 = 1;
		end
		if (figcount > 22 && start2 == 0) begin
			start2 = 1;
		end
		if (figcount > 45 && start3 == 0) begin
			start3 = 1;
		end
		if (figcount > 67 && start4 == 0) begin
			start4 = 1;
		end
		if (figcount > 90 && start5 == 0) begin
			start5 = 1;
		end
		if (figcount > 112 && start6 == 0) begin
			start6 = 1;
		end
		if (figcount > 135 && start7 == 0) begin
			start7 = 1;
		end
		if (figcount > 157 && start8 == 0) begin
			start8 = 1;
		end
      if (figcount > 180 && start9 == 0) begin
			start9 = 1;
		end
		if (figcount > 202 && start10 == 0) begin
			start10 = 1;
		end
		if (figcount > 225 && start11 == 0) begin
			start11 = 1;
		end
		if (figcount > 247 && start12 == 0) begin
			start12 = 1;
		end
      if (figcount > 270 && start13 == 0) begin
			start13 = 1;
		end
		if (figcount > 292 && start14 == 0) begin
			start14 = 1;
		end
		if (figcount > 315 && start15 == 0) begin
			start15 = 1;
		end
		if (figcount > 337 && start16 == 0) begin
			start16 = 1;
		end

		if (start1 == 1) begin
			M1 = M1 + 1'b1;
		end
		if (start2 == 1) begin
			M2 = M2 + 1'b1;
		end
		if (start3 == 1) begin
			M3 = M3 + 1'b1;
		end
		if (start4 == 1) begin
			M4 = M4 + 1'b1;
		end
		if (start5 == 1) begin
			M5 = M5 + 1'b1;
		end
		if (start6 == 1) begin
			M6 = M6 + 1'b1;
		end
		if (start7 == 1) begin
			M7 = M7 + 1'b1;
		end
		if (start8 == 1) begin
			M8 = M8 + 1'b1;
		end
		if (start9 == 1) begin
			M9 = M9 + 1'b1;
		end
		if (start10 == 1) begin
			M10 = M10 + 1'b1;
		end
		if (start11 == 1) begin
			M11 = M11 + 1'b1;
		end
		if (start12 == 1) begin
			M12 = M12 + 1'b1;
		end
		if (start13 == 1) begin
			M13 = M13 + 1'b1;
		end
		if (start14 == 1) begin
			M14 = M14 + 1'b1;
		end
		if (start15 == 1) begin
			M15 = M15 + 1'b1;
		end
		if (start16 == 1) begin
			M16 = M16 + 1'b1;
		end
		figcount = figcount + 1'b1;
	end
	
	end

   // send colors to VGA:
  always @ (posedge clk) begin
	
       if (figure0_1) 
			begin   
			if (Sim_Btn1==1) 
			begin
			  if(((M1>=400 && M1<=463) && (rand1[column1]==1)) || ((M2>=400 && M2<=463) && (rand2[column1]==1)) || 
			     ((M3>=400 && M3<=463) && (rand3[column1]==1)) || ((M4>=400 && M4<=463) && (rand4[column1]==1)) ||
				  ((M5>=400 && M5<=463) && (rand5[column1]==1)) || ((M6>=400 && M6<=463) && (rand6[column1]==1)) || 
			     ((M7>=400 && M7<=463) && (rand7[column1]==1)) || ((M8>=400 && M8<=463) && (rand8[column1]==1)) ||
				  ((M9>=400 && M9<=463) && (rand9[column1]==1)) || ((M10>=400 && M10<=463) && (rand10[column1]==1)) || 
			     ((M11>=400 && M11<=463) && (rand11[column1]==1)) || ((M12>=400 && M12<=463) && (rand12[column1]==1)) ||
				  ((M13>=400 && M13<=463) && (rand13[column1]==1)) || ((M14>=400 && M14<=463) && (rand14[column1]==1)) || 
			     ((M15>=400 && M15<=463) && (rand15[column1]==1)) || ((M16>=400 && M16<=463) && (rand16[column1]==1)))
			  begin
				R <= 0;
				G <= 4;
				B <= 1;
			  end
			else 
			begin
            R <= 7;
				G <= 0;
				B <= 0;
			  end
			end
			else begin
				R <= 2;
				G <= 2;	
				B <= 1;
			end
		end
		//second goal post
		else if (figure0_2) 
		begin   
			if (Sim_Btn2==1) 
			begin
			  if(((M1>=400 && M1<=463) && (rand1[column2]==1)) || ((M2>=400 && M2<=463) && (rand2[column2]==1)) || 
			     ((M3>=400 && M3<=463) && (rand3[column2]==1)) || ((M4>=400 && M4<=463) && (rand4[column2]==1)) ||
				  ((M5>=400 && M5<=463) && (rand5[column2]==1)) || ((M6>=400 && M6<=463) && (rand6[column2]==1)) || 
			     ((M7>=400 && M7<=463) && (rand7[column2]==1)) || ((M8>=400 && M8<=463) && (rand8[column2]==1)) ||
				  ((M9>=400 && M9<=463) && (rand9[column2]==1)) || ((M10>=400 && M10<=463) && (rand10[column2]==1)) || 
			     ((M11>=400 && M11<=463) && (rand11[column2]==1)) || ((M12>=400 && M12<=463) && (rand12[column2]==1)) ||
				  ((M13>=400 && M13<=463) && (rand13[column2]==1)) || ((M14>=400 && M14<=463) && (rand14[column2]==1)) || 
			     ((M15>=400 && M15<=463) && (rand15[column2]==1)) || ((M16>=400 && M16<=463) && (rand16[column2]==1)))
			begin
				R <= 0;
				G <= 4;
				B <= 1;
			  end 
			else
			begin
				R <= 7;
				G <= 0;
				B <= 0;
			end
			end
			else begin
				R <= 2;
				G <= 2;	
				B <= 1;
			end
		end
		//third goalpost
		else if (figure0_3) 
		begin   
			if (Sim_Btn3==1) 
			begin
			  if(((M1>=400 && M1<=463) && (rand1[column3]==1)) || ((M2>=400 && M2<=463) && (rand2[column3]==1)) || 
			     ((M3>=400 && M3<=463) && (rand3[column3]==1)) || ((M4>=400 && M4<=463) && (rand4[column3]==1)) ||
				  ((M5>=400 && M5<=463) && (rand5[column3]==1)) || ((M6>=400 && M6<=463) && (rand6[column3]==1)) || 
			     ((M7>=400 && M7<=463) && (rand7[column3]==1)) || ((M8>=400 && M8<=463) && (rand8[column3]==1)) ||
				  ((M9>=400 && M9<=463) && (rand9[column3]==1)) || ((M10>=400 && M10<=463) && (rand10[column3]==1)) || 
			     ((M11>=400 && M11<=463) && (rand11[column3]==1)) || ((M12>=400 && M12<=463) && (rand12[column3]==1)) ||
				  ((M13>=400 && M13<=463) && (rand13[column3]==1)) || ((M14>=400 && M14<=463) && (rand14[column3]==1)) || 
			     ((M15>=400 && M15<=463) && (rand15[column3]==1)) || ((M16>=400 && M16<=463) && (rand16[column3]==1)))
			begin
				R <= 0;
				G <= 4;
				B <= 1;
			end
		 else
		 begin
				R <= 7;
				G <= 0;
				B <= 0;
		  end
		  end
		  else begin
				R <= 2;
				G <= 2;	
				B <= 1;
		  end
		end
		//fourth goal post
		else if (figure0_4) 
		begin   
			if (Sim_Btn4==1) 
			begin
			  if(((M1>=400 && M1<=463) && (rand1[column4]==1)) || ((M2>=400 && M2<=463) && (rand2[column4]==1)) || 
			     ((M3>=400 && M3<=463) && (rand3[column4]==1)) || ((M4>=400 && M4<=463) && (rand4[column4]==1)) ||
				  ((M5>=400 && M5<=463) && (rand5[column4]==1)) || ((M6>=400 && M6<=463) && (rand6[column4]==1)) || 
			     ((M7>=400 && M7<=463) && (rand7[column4]==1)) || ((M8>=400 && M8<=463) && (rand8[column4]==1)) ||
				  ((M9>=400 && M9<=463) && (rand9[column4]==1)) || ((M10>=400 && M10<=463) && (rand10[column4]==1)) || 
			     ((M11>=400 && M11<=463) && (rand11[column4]==1)) || ((M12>=400 && M12<=463) && (rand12[column4]==1)) ||
				  ((M13>=400 && M13<=463) && (rand13[column4]==1)) || ((M14>=400 && M14<=463) && (rand14[column4]==1)) || 
			     ((M15>=400 && M15<=463) && (rand15[column4]==1)) || ((M16>=400 && M16<=463) && (rand16[column4]==1)))
			begin
				R <= 0;
				G <= 4;
				B <= 1;
			end
			else
			begin
				R <= 7;
				G <= 0;
				B <= 0;
			end
			end
			else 
			begin
				R <= 2;
				G <= 2;	
				B <= 1;
			end
		end
	
//moving figures start here:
		//first line from the left
      else if ((figure1_1 && rand1[0]==1) || (figure1_2 && rand2[0]==1) ||
		         (figure1_3 && rand3[0]==1) || (figure1_4 && rand4[0]==1) ||
					(figure1_5 && rand5[0]==1) || (figure1_6 && rand6[0]==1) ||
		         (figure1_7 && rand7[0]==1) || (figure1_8 && rand8[0]==1) ||
					(figure1_9 && rand9[0]==1) || (figure1_10 && rand10[0]==1) ||
		         (figure1_11 && rand11[0]==1) || (figure1_12 && rand12[0]==1) ||
					(figure1_13 && rand13[0]==1) || (figure1_14 && rand14[0]==1) ||
		         (figure1_15 && rand15[0]==1) || (figure1_16 && rand16[0]==1))
		begin
		   R <= 3'b101;
			G <= 3'b111;
			B <= 2'b01;	//green		
		end 
	   //second line from the left
      else if ((figure2_1 && rand1[1]==1) || (figure2_2 && rand2[1]==1) ||
		         (figure2_3 && rand3[1]==1) || (figure2_4 && rand4[1]==1) ||
					(figure2_5 && rand5[1]==1) || (figure2_6 && rand6[1]==1) ||
		         (figure2_7 && rand7[1]==1) || (figure2_8 && rand8[1]==1) ||
					(figure2_9 && rand9[1]==1) || (figure2_10 && rand10[1]==1) ||
		         (figure2_11 && rand11[1]==1) || (figure2_12 && rand12[1]==1) ||
					(figure2_13 && rand13[1]==1) || (figure2_14 && rand14[1]==1) ||
		         (figure2_15 && rand15[1]==1) || (figure2_16 && rand16[1]==1))
      begin
			R <= 3'b011;
			G <= 3'b110;
			B <= 2'b11; //blue
		end
		//third line from the left
      else if ((figure3_1 && rand1[2]==1) || (figure3_2 && rand2[2]==1) ||
		         (figure3_3 && rand3[2]==1) || (figure3_4 && rand4[2]==1) ||
					(figure3_5 && rand5[2]==1) || (figure3_6 && rand6[2]==1) ||
		         (figure3_7 && rand7[2]==1) || (figure3_8 && rand8[2]==1) ||
					(figure3_9 && rand9[2]==1) || (figure3_10 && rand10[2]==1) ||
		         (figure3_11 && rand11[2]==1) || (figure3_12 && rand12[2]==1) ||
					(figure3_13 && rand13[2]==1) || (figure3_14 && rand14[2]==1) ||
		         (figure3_15 && rand15[2]==1) || (figure3_16 && rand16[2]==1))
		begin
		   R <= 3'b111;
			G <= 3'b111;
			B <= 2'b10;	//yellow
		end
		//fourth line from the left
      else if ((figure4_1 && rand1[3]==1) || (figure4_2 && rand2[3]==1) ||
		         (figure4_3 && rand3[3]==1) || (figure4_4 && rand4[3]==1) ||
					(figure4_5 && rand5[3]==1) || (figure4_6 && rand6[3]==1) ||
		         (figure4_7 && rand7[3]==1) || (figure4_8 && rand8[3]==1) ||
					(figure4_9 && rand9[3]==1) || (figure4_10 && rand10[3]==1) ||
		         (figure4_11 && rand11[3]==1) || (figure4_12 && rand12[3]==1) ||
					(figure4_13 && rand13[3]==1) || (figure4_14 && rand14[3]==1) ||
		         (figure4_15 && rand15[3]==1) || (figure4_16 && rand16[3]==1))
		begin
			R <= 3'b100;
			G <= 3'b100;
			B <= 2'b11;//purple

		end else	if (letter1_on) begin
			R <= 3'b111;
			G <= 3'b111;
			B <= 2'b11;
		
		end else if (letter2_on) begin
			R <= 3'b101;
			G <= 3'b111;
			B <= 2'b11;
		end else if (letter3_on) begin
			R <= 3'b111;
			G <= 3'b101;
			B <= 2'b11;
		end else if (letter4_on) begin
			R <= 3'b111;
			G <= 3'b111;
			B <= 2'b10;
		end else if (letter5_on) begin
			R <= 3'b110;
			G <= 3'b111;
			B <= 2'b10;
		end else if (letter6_on) begin
			R <= 3'b101;
			G <= 3'b011;
			B <= 2'b11;
			
		end else	if (letter7_on) begin
			R <= 3'b111;
			G <= 3'b000;
			B <= 2'b00;
		
		end else if (letter8_on) begin
			R <= 3'b111;
			G <= 3'b000;
			B <= 2'b00;
		end else if (letter9_on) begin
			R <= 3'b111;
			G <= 3'b000;
			B <= 2'b00;
		end else if (letter10_on) begin
			R <= 3'b111;
			G <= 3'b000;
			B <= 2'b00;
		end else if (letter11_on) begin
			R <= 3'b111;
			G <= 3'b000;
			B <= 2'b00;
		end else if (letter12_on) begin
			R <= 3'b111;
			G <= 3'b000;
			B <= 2'b00;
			
		end else if (digit_0_on) begin
			R <= 3'b111;
			G <= 3'b111;
			B <= 2'b11;
		end
		else if (digit_1_on) begin
			R <= 3'b111;
			G <= 3'b111;
			B <= 2'b11;
		end
		else if (digit_2_on) begin
			R <= 3'b111;
			G <= 3'b111;
			B <= 2'b11;
		end
		else if (digit_21_on) begin
			R <= 3'b111;
			G <= 3'b111;
			B <= 2'b11;
		end		
		
		else if (digit_3_on) begin
			R <= 3'b111;
			G <= 3'b000;
			B <= 2'b00;
		end
		else if (digit_4_on) begin
			R <= 3'b111;
			G <= 3'b000;
			B <= 2'b00;
		end
		
		else if (digit_5_on) begin
			R <= 3'b111;
			G <= 3'b000;
			B <= 2'b00;
		end

		else begin    // if you are outside the valid region
         R <= 0;	// display black
         G <= 0;
         B <= 0;
      end
   end

	
endmodule


